import { getMixin } from "./mixin";
import { omitByKeys } from "../object";

function bindAttached(self, options) {

}

function bindDetached(self, options) {

}

export function mComponent(mix) {
    let _s = omitByKeys(mix, ['attached', 'detached']);
    _s = {..._s,  ...omitByKeys(Object.getPrototypeOf(mix), ['constructor', 'attached', 'detached'])};
    _s = {..._s, ..._s.exports};

    if (mix && mix.mixins) {
        mix.mixins.forEach(function (mixinkey) {
            let _mix = getMixin(mixinkey) || {};
            _s.data = {..._s.data, ..._mix.data};
            _s.properties = {..._s.properties, ..._mix.properties};
            _s.methods = {..._s.methods, ..._mix.methods}
        });
    }

    let def = Object.assign(
        _s,
        {
            attached (options = {}) {
                let self = this;
                self.$opt = options;
                bindAttached(self, ...options);
                mix.attached && mix.attached.apply(this, options)
            },
            detached (options = {}) {
                let self = this;
                bindDetached(self, ...options);
                mix.detached && mix.detached.apply(this, options)
            },
        }
    );
    Component(def);
}